clear all
set more off

cd            "/CGR_credit"
local out2 = "/home/user/h080700/private/A_D/CGR_credit/outregsQJE/"
use "step001_credit_QJE.dta"

tsset firm_id time

*** define treatment as given inflation TIMES treatment status
gen Treat=treatment_old*infl

*** winsorize firm expected price change
winsor dprez, gen(dprez_w) p(0.02)

local controls0=" l2.dprez_w  i.l2.sitimp5 i.l2.occtot i.l2.sitgen i.l2.promig i.l2.liquid"	

*** restrict the sample only to the period with treatment and control groups
keep if time>=217 


*** horizon 0 ******************************************************************
*gen FC = primainfo
cap drop FC
gen FC = primainfo 
ivreghdfe FC `controls0' ///
	(l.it12_all = l.Treat) [aw=peso] , ///
	ffirst dkraay(2) absorb(i.setton5#i.trim  i.trim )

	       outreg2 using "`out2'Appendix_Table07_PanelE.dta", replace dec(3)  ///
	addstat( "1st stage F stat", e(widstat))	
	
	capture drop smpl1
	gen smpl1=1 if e(sample)
	
ivreghdfe l.it12_all  l.Treat `controls0' ///
	 [aw=peso] if smpl1==1, ///
	 dkraay(2) absorb(i.setton5#i.trime )
        outreg2 using "`out2'Appendix_Table07_PanelE_first_stage.dta", replace dec(3)  ///
		
*** horizon 1 ******************************************************************
*gen FC1 = f.primainfo
gen FC1 = f.primainfo + primainfo
ivreghdfe FC1 `controls0' ///
	(l.it12_all = l.Treat) [aw=peso] , ///
	dkraay(2) absorb(i.setton5#i.trime)
	outreg2 using "`out2'Appendix_Table07_PanelE.dta", append dec(3)  ///
	addstat( "1st stage F stat", e(widstat))	
	
	capture drop smpl1
	gen smpl1=1 if e(sample)
	
ivreghdfe l.it12_all  l.Treat `controls0' ///
	 [aw=peso] if smpl1==1, ///
	 dkraay(2) absorb(i.setton5#i.trime )
        outreg2 using "`out2'Appendix_Table07_PanelE_first_stage.dta", append dec(3)  ///
	

	
***	horizon 2
gen FC2=f2.primainfo + f.primainfo + primainfo
ivreghdfe FC2 `controls0' ///
	(l.it12_all = l.Treat) [aw=peso] , ///
	dkraay(2) absorb(i.setton5#i.trime)
	
	
	outreg2 using "`out2'Appendix_Table07_PanelE.dta", append dec(3) ///
	addstat( "1st stage F stat", e(widstat))	
	
	capture drop smpl1
	gen smpl1=1 if e(sample)
	
ivreghdfe l.it12_all  l.Treat `controls0' ///
	 [aw=peso] if smpl1==1, ///
	 dkraay(2) absorb(i.setton5#i.trime )
        outreg2 using "`out2'Appendix_Table07_PanelE_first_stage.dta", append dec(3)  ///
	
